package com.hy.thread;

import com.hy.admin.service.MessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AddMessageThread implements Runnable{
    protected final Logger logBase = LoggerFactory.getLogger(AddMessageThread.class);

    MessageService messageService = (MessageService) SpringContextUtil.getBean("messageServiceImpl");

    private Long memberId;

    public AddMessageThread(Long memberId) {
        this.memberId = memberId;
    }

    @Override
    public void run() {
        if(memberId != null){
            try {
                Boolean result = false;
                while(!result) {
                    //如果插入数据失败，5秒后继续插入直到成功为止
                    Thread.sleep(5000);
                    result = messageService.addMessageForCourse(memberId);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
